package com.video.list.player.fragment

import android.os.Bundle
import android.provider.MediaStore
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import androidx.fragment.app.Fragment
import com.bumptech.glide.Glide
import com.video.list.player.R
import com.video.list.player.VideoManager
import com.video.list.player.bean.VideoInfo

class VideoFragment : Fragment() {

    var mVideoContainer: FrameLayout? = null
    var mVideoInfo: VideoInfo? = null

    companion object{
        fun newInstance(videoInfo: VideoInfo): VideoFragment {
            val args = Bundle()
            args.putParcelable("data",videoInfo)
            val fragment = VideoFragment()
            fragment.arguments = args
            return fragment
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_video,container,false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        mVideoInfo =  arguments?.getParcelable<VideoInfo>("data")

        mVideoContainer = view.findViewById(R.id.video_container)
        val videoCoverIv = view.findViewById<ImageView>(R.id.iv_video_cover)
        Glide.with(this).load(mVideoInfo!!.cover).into(videoCoverIv)

        mVideoContainer?.addView(VideoManager.instance.playerView)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Log.i("jiao","fragment onCreate")
    }

    override fun onResume() {
        super.onResume()
        Log.i("jiao","fragment onResume ${mVideoInfo!!.cover}")
    }

    override fun onPause() {
        super.onPause()
        Log.i("jiao","fragment onPause ${mVideoInfo!!.cover}")
    }

    override fun onStop() {
        super.onStop()
        Log.i("jiao","fragment onStop ${mVideoInfo!!.cover}")
    }

    override fun onDestroyView() {
        super.onDestroyView()
        Log.i("jiao","fragment onDestroyView ${mVideoInfo!!.cover}")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.i("jiao","fragment onDestroy ${mVideoInfo!!.cover}")
    }

    override fun onDetach() {
        super.onDetach()
        Log.i("jiao","fragment onDetach ${mVideoInfo!!.cover}")
    }

}